package com.liuyongyi.livepush;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
//先检查权限，如果已经赋予了权限，则不提示，如果没有给，那就给到权限
public class MainActivity extends Activity{
    private String[] MANIFEST={Manifest.permission.RECORD_AUDIO};
    private static int PERMISSIONRESULT = 10000;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        for (int i = 0; i < MANIFEST.length; i++) {
            if(ContextCompat.checkSelfPermission(this, MANIFEST[i]) == PackageManager.PERMISSION_DENIED){
                //没有权限
                ActivityCompat.requestPermissions(this,new String[]{MANIFEST[i]},PERMISSIONRESULT);
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
